import {getApi,postApi} from '../request'
import {getUserRequestData,EditUserRequestData} from './types'



//获取用户数
export async function userCounts() {
  try {
    const res = await getApi('user/userCounts');
    return res;
  } catch (error) {
    console.error(error); // 处理错误
    return "error-0000"
  }
}

//获取个人简介
export async function userGetContact(data : getUserRequestData) {
    if (data.article_id.length<8)
    { console.log("提交数据不符合要求！！！"); return "data-0000"; }

    try {
      const res = await getApi('user/getContact',{
        "article_id":data.article_id
      });
      return res;
  
    } catch (error) {
      console.error(error); // 处理错误
      return "error-0000"
    }
  }

//获取用户信息
export async function userDetials() {
    try {
      const res = await getApi('user/detials');
      return res;
  
    } catch (error) {
      console.error(error); // 处理错误
      return "error-0000"
    }
  }

//编辑用户信息
export async function userEdit(data:EditUserRequestData) {
    if (data.career_tags.length<2
         || data.introduction.length<4 || data.nickname.length<4)
    { console.log("提交数据不符合要求！！！"); return "data-0000"; }

    try {
      const res = await postApi('user/edit',{
        "avatar":data.avatar,
        "career_tags":data.career_tags,
        "nickname":data.nickname,
        "introduction":data.introduction,
        "background_image":data.background_image
             });
      return res;
  
    } catch (error) {
      console.error(error); // 处理错误
      return "error-0000"
    }
  }